package com.lvyq.myplayer.widget.ranking

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.model.ranking.RankingInfo
import com.squareup.picasso.Picasso

/**
 * 文件描述：TheChartView
 * 作者：lvyq
 * 创建时间：2025-06-03
 * 修改时间：2025-06-03
 */
class TheChartView: RelativeLayout {
    lateinit var tv_title: TextView
    lateinit var img: ImageView
    lateinit var musicName1:TextView
    lateinit var musicName2:TextView
    lateinit var musicName3:TextView
    lateinit var singerName1:TextView
    lateinit var singerName2:TextView
    lateinit var singerName3:TextView

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    init {
            var view = View.inflate(context, R.layout.item_the_chart, this)
            tv_title=view.findViewById(R.id.tv_title)
            img=view.findViewById(R.id.img)
            singerName1=view.findViewById(R.id.singerName1)
            singerName2=view.findViewById(R.id.singerName2)
            singerName3=view.findViewById(R.id.singerName3)
            musicName1=view.findViewById(R.id.musicName1)
            musicName2=view.findViewById(R.id.musicName2)
            musicName3=view.findViewById(R.id.musicName3)
    }

    fun setData(data: RankingInfo) {
        tv_title.text=data.name
        if (data.bgImg!=null){
            Picasso.with(context).load(data.bgImg).into(img)
        }
        var content = data.content
        if (content!=null){
            var splitContent = content?.split("[#]")


            var splitData1 = splitContent?.get(0)?.split("[-]")
            var splitData2 = splitContent?.get(1)?.split("[-]")
            var splitData3 = splitContent?.get(2)?.split("[-]")

            musicName1.text=splitData1?.get(0) ?:""
            musicName2.text=splitData2?.get(0) ?:""
            musicName3.text=splitData3?.get(0) ?:""
            singerName1.text= splitData1?.get(1) ?:""
            singerName2.text= splitData2?.get(1) ?:""
            singerName2.text= splitData3?.get(1) ?:""
        }

    }
}